# JavaScript API

Rsbuild provides a complete set of JavaScript APIs for developers to build higher level tools or frameworks on top of Rsbuild.

Rsbuild's JavaScript API can be used in Node.js, Deno, or Bun.

## Access Example

Here is a basic example of how to access the Rsbuild JavaScript API.

### 1. Install Rsbuild

You need to install the `@rsbuild/core` package:

import { PackageManagerTabs } from '@theme';

<PackageManagerTabs command="add @rsbuild/core -D" />

### 2. Create an Rsbuild Instance

You can call the [createRsbuild](/api/javascript-api/core#creatersbuild) method to create an Rsbuild instance:

```ts
import { createRsbuild } from '@rsbuild/core';

const rsbuild = await createRsbuild();
```

The `createRsbuild` method provides some options, which you can learn more about in the [API - createRsbuild](/api/javascript-api/core#creatersbuild).

### 3. Call Rsbuild Instance Method

The Rsbuild instance provides some methods, which you can use it according to the usage scenarios.

To start local development, it is recommended to use the [rsbuild.startDevServer](/api/javascript-api/instance#rsbuildstartdevserver) method, which will start a local dev server.

```ts
await rsbuild.startDevServer();
```

After successfully starting dev server, you can see the following logs:

```
  ➜ Local:    http://localhost:3000
  ➜ Network:  http://192.168.0.1:3000
```

To deploy the App to production environment, it is recommended to use the [rsbuild.build](/api/javascript-api/instance#rsbuildbuild) method, which will build the production outputs.

```ts
await rsbuild.build();
```

> For more introduction of Rsbuild instance methods, please read the [Rsbuild Instance](/api/javascript-api/instance) chapter.

After completing the above three steps, you have learned the basic usage of Rsbuild. Next, you can customize the build process through the Rsbuild plugin and Rsbuild configs.

## Exports Format

Rsbuild provides exports in both ES Modules and CommonJS formats:

```js title="index.mjs"
import { createRsbuild } from '@rsbuild/core';
```

```js title="index.cjs"
const { createRsbuild } = require('@rsbuild/core');
```

> It is recommended to use ES modules format, which is more in line with the community standards.
